package stack;

import java.util.Arrays;

public class MyStack {
    public int [] elem;
    public int usedSize;
    public static final int DEFAULT_CAPACITY=5;
    public MyStack(){
        elem=new int[DEFAULT_CAPACITY];
    }
    public void push(int val){
        if (isFull()){
            elem= Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize]=val;
        usedSize++;
    }
    public boolean isFull(){
        return usedSize== elem.length;
    }
    public int pop(){
        if(isEmpty()){
            return -1;
        }
        int ret=elem[usedSize-1];
        usedSize--;
        return ret;
    }
    public int peek(){
        if(isEmpty()){
            return -1;
        }
        int ret=elem[usedSize-1];
        return ret;
    }
    public boolean isEmpty(){
        return usedSize==0;
    }
}
